package cn.ezios.huo.system.biz.controller;

import cn.ezios.huo.system.dao.domain.SysMenu;
import cn.ezios.huo.system.dao.dto.SysMenuDTO;
import cn.ezios.huo.system.dao.vo.SysMenuVO;
import cn.ezios.huo.system.dao.service.SysMenuService;
import cn.ezios.huo.common.mvc.Ret;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("sys/menu")
@RequiredArgsConstructor
public class SysMenuController {

    private final SysMenuService sysMenuService;

    @PostMapping("")
    public Ret add(@RequestBody SysMenu sysMenu) {
        boolean save = sysMenuService.save(sysMenu);
        return save ? Ret.ok() : Ret.error();
    }

    @PutMapping("")
    public Ret update(@RequestBody SysMenu sysMenu) {
        boolean update = sysMenuService.updateById(sysMenu);
        return update ? Ret.ok() : Ret.error();
    }

    @GetMapping("{id}")
    public Ret get(@PathVariable("id") String id) {
        SysMenu sysMenu = sysMenuService.getById(id);
        return sysMenu != null ? Ret.ok(sysMenu) : Ret.error("未找到");
    }

//    @GetMapping("page")
//    public Ret page(@RequestParam(value = "current", defaultValue = "1") Integer current,
//    @RequestParam(value = "size", defaultValue = "10") Integer size,SysMenuDTO dto) {
//       IPage <SysMenuVO> page = sysMenuService.queryPage(current,size,dto);
//            return Ret.ok(page);
//    }

    @DeleteMapping("{id}")
    public Ret delete(@PathVariable("id") String id) {
        boolean remove = sysMenuService.removeById(id);
        return remove ? Ret.ok() : Ret.error();
    }

    @PostMapping("copy/{id}")
    public Ret copy(@PathVariable("id") String id) {
        boolean copy = sysMenuService.copyMenu(id);
        return copy ? Ret.ok() : Ret.error();
    }
}
